<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Models\product\ProductModel;
use Carbon\Carbon;
use lxs\api\ApiResponse;
use lxs\tools\Tools;

class IndexController extends Controller {

    /**
     * 获取首页产品列表
     */
    public function index()
    {
        $config['user_prr'] = Tools::Config('user.PRR');

        $list[]['product'] = ProductModel::orderBy('sort', 'desc')
                ->where('deleted_at', 0)
                ->orderBy('id', 'desc')
                ->limit(3)->get()->toArray();
        $list[]['product'] = ProductModel::orderBy('sort', 'desc')
                ->where('deleted_at', 0)
                ->orderBy('id', 'desc')
                ->limit(3)->offset(3)->get()->toArray();
        $list[]['product'] = ProductModel::orderBy('sort', 'desc')
                ->where('deleted_at', 0)->orderBy('id', 'desc')
                ->limit(3)->offset(6)->get()->toArray();

        foreach ($list as $k => $v) {
            foreach ($v['product'] as $kk => $vv) {
                $list[$k]['product'][$kk]['live_time'] = Carbon::createFromTimestamp($vv['live_time'])->format('Y-m-d');
            }
        }

        return ApiResponse::apiResponseData(200, "获取成功", [
            'product_list' => $list,
            'config' => $config,
        ]);

    }

}
